package com.tledu.equipment.controller;

import com.tledu.common.annotation.Log;
import com.tledu.common.core.controller.BaseController;
import com.tledu.common.core.domain.AjaxResult;
import com.tledu.common.core.page.TableDataInfo;
import com.tledu.common.enums.BusinessType;
import com.tledu.common.utils.poi.ExcelUtil;
import com.tledu.equipment.domain.EquipmentUse;
import com.tledu.equipment.domain.vo.EquipmentUseVO;
import com.tledu.equipment.service.IEquipmentInfoService;
import com.tledu.equipment.service.IEquipmentUseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备使用记录Controller
 * 
 * @author ruoyi
 * @date 2024-08-29
 */
@RestController
@RequestMapping("/equipment/equipmentuse")
public class EquipmentUseController extends BaseController
{
    @Autowired
    private IEquipmentUseService equipmentUseService;

    @Autowired
    private IEquipmentInfoService equipmentInfoService;

    /**
     * 查询设备使用记录列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:equipmentuse:list')")
    @GetMapping("/list")
    public TableDataInfo list(EquipmentUse equipmentUse)
    {
        startPage();
        List<EquipmentUseVO> list = equipmentUseService.selectEquipmentUseList(equipmentUse);
        return getDataTable(list);
    }

    /**
     * 导出设备使用记录列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:equipmentuse:export')")
    @Log(title = "设备使用记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EquipmentUse equipmentUse)
    {
        List<EquipmentUseVO> list = equipmentUseService.selectEquipmentUseList(equipmentUse);
        ExcelUtil<EquipmentUseVO> util = new ExcelUtil<EquipmentUseVO>(EquipmentUseVO.class);
        util.exportExcel(response, list, "设备使用记录数据");
    }

    /**
     * 获取设备使用记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('equipment:equipmentuse:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(equipmentUseService.selectEquipmentUseById(id));
    }

    /**
     * 新增设备使用记录
     */
    @PreAuthorize("@ss.hasPermi('equipment:equipmentuse:add')")
    @Log(title = "设备使用记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquipmentUse equipmentUse)
    {
        return toAjax(equipmentUseService.insertEquipmentUse(equipmentUse));
    }

    /**
     * 修改设备使用记录
     */
    @PreAuthorize("@ss.hasPermi('equipment:equipmentuse:edit')")
    @Log(title = "设备使用记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquipmentUse equipmentUse)
    {
        return toAjax(equipmentUseService.updateEquipmentUse(equipmentUse));
    }

    /**
     * 删除设备使用记录
     */
    @PreAuthorize("@ss.hasPermi('equipment:equipmentuse:remove')")
    @Log(title = "设备使用记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(equipmentUseService.deleteEquipmentUseByIds(ids));
    }


}
